How to print a groupby object

32

import pandas as pd
df = pd.DataFrame({'A': ['one', 'one', 'two', 'three', 'three', 'one'], 'B': range(6)})
print(df)
#       A  B
#0    one  0
#1    one  1
#2    two  2
#3  three  3
#4  three  4
#5    one  5

grouped_df = df.groupby('A')

for key, item in grouped_df:
    print(grouped_df.get_group(key), "\n\n")

#             A  B
#A                
#one   0    one  0
#      1    one  1
#      5    one  5
#two   2    two  2
#three 3  three  3
#      4  three  4

Comments

Submit
0 Comments